package business.sale.entities;

import java.math.BigDecimal;

import business.article.entities.Article;
import sale.entities.ArticleBillvo;

public class ArticleBill {

	private int idBill;
	private int idLine;
	private Article art;
	private double unitPrice;
	private double Totalprice;
	private int quant;

	public int getIdBill() {
		return idBill;
	}

	public void setIdBill(int idBill) {
		this.idBill = idBill;
	}

	public int getIdLine() {
		return idLine;
	}

	public void setIdLine(int idLine) {
		this.idLine = idLine;
	}

	public Article getArt() {
		return art;
	}

	public void setArt(Article art) {
		this.art = art;
	}

	public double getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(double unitPrice) {
		this.unitPrice = unitPrice;
	}

	public double getTotalprice() {
		return Totalprice;
	}

	public void setTotalprice(double totalprice) {
		Totalprice = totalprice;
	}

	public int getQuant() {
		return quant;
	}

	public void setQuant(int quant) {
		this.quant = quant;
	}

	public ArticleBill(ArticleBillvo ab) {
		if (ab != null) {
			this.idBill = ab.getIdBill();
			this.idLine = ab.getIdLine();
			this.unitPrice = ab.getUnitPrice();
			this.Totalprice = ab.getTotalprice();
			this.quant = ab.getQuant();
			this.art = new Article(ab.getArt());
		}
	}

	public ArticleBill(Article a, int billId, int i) {
		if(a!=null){
			this.art = a;
			this.idBill = billId;
			this.idLine = i;
			this.quant=1;
			this.unitPrice = a.getPrice();
			this.Totalprice = a.getPrice();
		}
	}

	public ArticleBillvo toVO() {
		return new ArticleBillvo(this.idBill, this.idLine, this.art.toVO(),
				this.unitPrice, this.Totalprice, this.quant);
	}

	public void updateOneUp() {
		BigDecimal aux = new BigDecimal(this.Totalprice);
		aux = aux.add(new BigDecimal(this.unitPrice)); 
		this.Totalprice = aux.doubleValue();
		this.quant++;
	}
}
